package Chart;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

@SuppressWarnings("serial")
public class Main extends ApplicationFrame implements ActionListener {

	/**
	 * @param args
	 */

	public Main(String title) {
		super(title);
		setPreferredSize(new java.awt.Dimension(1024, 700));

		// create Panel Menu
		JPanel jPanelMenu = new JPanel();
		jPanelMenu.setSize(80, 80);
		jPanelMenu.setLayout(new GridLayout(25, 25));

		// create Panel Button
		JPanel jPanelButton = new JPanel();
		jPanelButton.setSize(200, 30);
		jPanelButton.setLocation(300, 230);
		jPanelButton.setLayout(new GridLayout(1, 0));

		// create Menu bar
		JMenuBar mb = new JMenuBar();
		jPanelMenu.add(mb);

		// create menu File
		JMenu jFile = new JMenu("File");
		mb.add(jFile);

		// create item menu File
		JMenuItem jTimeChart = new JMenuItem("TimeChart");
		jFile.add(jTimeChart);
		jTimeChart.addActionListener(this);
		jFile.addSeparator();

		JMenuItem jPieChart = new JMenuItem("PieChart");
		jFile.add(jPieChart);
		jPieChart.addActionListener(this);
		jFile.addSeparator();

		JMenuItem jExit = new JMenuItem("Exit");
		jFile.add(jExit);
		jExit.addActionListener(this);

		// create menu Help
		JMenu jHelp = new JMenu("Help");
		mb.add(jHelp);

		// create item menu Help
		JMenuItem jAbout = new JMenuItem("About");
		jHelp.add(jAbout);
		jAbout.addActionListener(this);

		// create button
		JButton btn_TimeChart = new JButton("TimeChart");
		btn_TimeChart.addActionListener(this);
		jPanelButton.add(btn_TimeChart);

		JButton btn_PieChart = new JButton("PieChart");
		btn_PieChart.addActionListener(this);
		jPanelButton.add(btn_PieChart);

		// add vao frame
		this.add(jPanelButton);
		this.add(jPanelMenu);

	}

	public static void main(String[] agrs) throws IOException {

		Main demo = new Main("Demo");
		demo.pack();
		RefineryUtilities.centerFrameOnScreen(demo);
		demo.setVisible(true);

	}

	@Override
	public void actionPerformed(ActionEvent ae) {
		if (ae.getActionCommand().equals("TimeChart")) {
			try {
				TimeChart demo = new TimeChart("Time Chart");
				demo.pack();
				RefineryUtilities.centerFrameOnScreen(demo);
				demo.setVisible(true);
				this.setVisible(false);
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else if (ae.getActionCommand().equals("PieChart")) {
			PieChart pieFrame = new PieChart("Pie Chart");
			pieFrame.pack();
			RefineryUtilities.centerFrameOnScreen(pieFrame);
			pieFrame.setVisible(true);
			this.setVisible(false);
		} else if (ae.getActionCommand().equals("Exit")) {
			System.exit(0);
		} else if (ae.getActionCommand().equals("About")) {
			JLabel label = new JLabel("<html>Line 1<br>Line 2</html>",
					JLabel.CENTER);
			JFrame frame = new JFrame("About");
			frame.setPreferredSize(new java.awt.Dimension(250, 250));
			frame.getContentPane().add(label);
			frame.pack();
			RefineryUtilities.centerFrameOnScreen(frame);
			frame.setVisible(true);
		}
	}

}
